<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitPackageAsset extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 福袋资产
        Schema::create('package_assets', function (Blueprint $table) {
            $table->comment = '福袋';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->string('title')->comment('标题')->nullable();

            $table->integer('activity_id')->index()->comment('活动id，盲盒id、一番赏id、抽奖id、扭蛋机id'); // 用户id
            $table->string('activity_type', 20)->index()->comment('对应活动类型, box yifanshang lottery egg_lottery'); // 用户id

            $table->integer('sku_total')->unsigned()->default(0)->comment('抽盒内小盒子数量'); // 精度，默认为0。 即单位为1

            // $table->integer('root_user_id')->unsigned()->nullable()->comment('最初归属用户id'); 
            $table->integer('user_id')->unsigned()->nullable()->comment('当前归属用户id'); 

            $table->integer('pay_order_id')->unsigned()->nullable()->comment('支付订单id'); 

            $table->tinyInteger('status')->unsigned()->default(0)->index()->comment('状态 0为未开盒 1为已开盒 2已转赠');

            $table->softDeletes();
            $table->timestamps();
        });

        // 福袋内奖项
        Schema::create('package_skus', function (Blueprint $table) {
            $table->comment = '福袋内奖项';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('package_asset_id')->index()->comment('package id');

            // $table->integer('root_user_id')->unsigned()->nullable()->comment('最初归属用户id'); 
            $table->integer('user_id')->unsigned()->nullable()->comment('当前归属用户id'); 

            $table->string('title', 100)->comment('标题');
            $table->string('number', 100)->nullable()->comment('编号');
            $table->string('thumb', 255)->nullable()->comment('封面');

            $table->integer('money_price')->unsigned()->nullable()->comment('人民币价格');     // 价格
            $table->integer('score_price')->unsigned()->nullable()->comment('积分价格');     // 价格
            
            $table->integer('total')->unsigned()->default(0)->comment('数量'); 

            $table->integer('activity_id')->index()->comment('活动id，盲盒id、一番赏id、抽奖id、扭蛋机id'); // 用户id
            $table->string('activity_type', 20)->index()->comment('对应活动类型, box yifanshang lottery egg_lottery');

            $table->tinyInteger('sku_type')->index()->comment('奖品类型, 1为自定义实物，2为绑定商城商品 3为平台虚拟资产  4为无任何奖品');

            $table->boolean('is_return_saleable')->default(1)->comment('是否可以返售给平台 0为否 1为是');
            $table->boolean('is_resaleable')->default(1)->comment('是否可以转售');
            $table->boolean('is_giveable')->default(1)->comment('是否可以赠送');

            $table->integer('pay_order_id')->unsigned()->nullable()->comment('支付订单id'); 
            $table->integer('pick_order_id')->unsigned()->nullable()->comment('提取订单id'); 

            $table->integer('room_id')->index()->nullable()->comment('房间id，部分活动有此字段'); // 用户id

            $table->json('open_index')->nullable()->comment('抽出的序号数组，可能多次抽出');
            $table->json('options')->nullable()->comment('其它选项');

            $table->timestamp('return_saled_at')->nullable()->comment('返售时间'); 
            $table->timestamp('picked_at')->nullable()->comment('提取时间'); 
            $table->timestamp('resaled_at')->nullable()->comment('转售时间'); 

            $table->integer('return_redpack')->nullable()->comment('返售红包'); 
            $table->integer('return_score')->nullable()->comment('返售积分'); 
            $table->integer('return_money')->nullable()->comment('返售人民币(原路返回)'); 

            $table->tinyInteger('status')->unsigned()->default(1)->index()->comment('1为待处理  2为已发货  3为已返售  4为已转售 5为转售中');

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('package_assets');
        Schema::dropIfExists('package_skus');
    }
}
